#include <lpc23xx.h>
#include "LCD.h"
void FIQ_Handler (void)__irq; 
void HardwareInit (void);

unsigned int flasher;
unsigned int delay;	
int main (void)
{
			
HardwareInit ();


    lcd_init();					   //
	lcd_clear();				  //
	set_cursor(2,0);			   // Agaf=/
    lcd_print("MAM Example");	 //   
while(1)
{

FIO2CLR         = 0x000000FF;

for(flasher =1;flasher<0x00000100;flasher = flasher <<1)
    {
       FIO2SET = flasher; 
        for(delay = 0;delay<0x30000;delay++)				  	//simple delay loop
        {
          ;
        }
    }
  FIO2CLR = 0x000000FF;
}  
    
 

return(0);
}

void FIQ_Handler (void)__irq
{
  
unsigned char debounce; 
if (MAMTIM == 0x00000007)                   //Check the state of the MAM
{
MAMCR 		= 0x00000000;                   //Disable the MAM
MAMTIM 		= 0x00000004;                   //Set the access time to four clocks 
MAMCR 		= 0x00000002;                   // Fully enable the MAM
}
else
{
MAMCR 		= 0x00000000;                   //Disable the MAM
MAMTIM		= 0x00000007;                   //Set the access time to seven clocks
}
for(debounce = 0;debounce<0xFE;debounce++) //Debounce the switch
  {
    ;
  }


EXTINT  		= 0x00000001;			    //Clear the peripheral interrupt flag
}

void HardwareInit (void)
{
PINSEL0         = 0x00000000;
PINSEL1         = 0x00000000;
PINSEL2         = 0x00000000;
PINSEL3         = 0x00000000;
PINSEL4         = 0x00000000;
PINSEL5         = 0x00000000;
PINSEL6         = 0x00000000;
PINSEL7         = 0x00000000;
PINSEL8         = 0x00000000;
PINSEL9         = 0x00000000;
PINSEL10        = 0x00000000;
    
IODIR0          = 0x00000000;
IODIR1          = 0x00000000;
IOSET0          = 0x00000000;
IOSET1          = 0x00000000;
   
FIO0DIR         = 0x00000000;
FIO1DIR         = 0x00000000;
FIO2DIR         = 0x00000000;
FIO3DIR         = 0x00000000;
FIO4DIR         = 0x00000000;
    
FIO0SET         = 0x00000000;
FIO1SET         = 0x00000000;
FIO2SET         = 0x00000000;
FIO3SET         = 0x00000000;
FIO4SET         = 0x00000000;					

PINSEL4 	    = 0x00100000;						//Enable the EXTINT1 interrupt
EXTMODE         = 0x00000001;                       //Set INT0 to edge sensetive mode
EXTPOLAR        = 0x00000001;                       //Select rising edge
EXTINT          = 0x00000001;                       //Clear the interrupt flags
VICIntSelect    = 0x00004000;
VICIntEnable    = 0x00004000;						//enable interrupt
FIO2DIR         = 0x000000FF;   
FIO2MASK        = 0xFFFFFF00;
    
}
